﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDD4Fun.AircraftMoniter;
using DDD4Fun.Factory;
using DDD4Fun.Strategy;
using DDD4Fun.Bridge;
using DDD4Fun.Repository;
using DDD4Fun.Specification;
using DDD4Fun.Observer;
using System.Linq.Expressions;
using DDD4Fun.State;
using DDD4Fun.Ducks;
using DDD4Fun.Mediator;
using DDD4Fun.Common;
using System.Threading;


namespace DDD4Fun
{
    class Program
    {
        delegate bool del(ClassicFruit i);
        static void Main(string[] args)
        {
            int[] ssss = { 555, 125, 955, 9, 5, 3, 7, 11, 6, 2, 4, 0, 12, 18, 855, 154, 1024, 5102 };

            ssss.quicksort(0, ssss.Length - 1);
            return;
            CTryFinallyUser user = CTryFinally.TestUserReturnInTry();
            return;
            CXB.go(); return;
            
            CDelegate.TestDelegate(); return;
            CList.TestList();
             return;
            CCopy.TestCopy();
            CEquals.TestEqual();
            return;
            CFormat.getPerson("ch");
            CFormat.getPerson("eg");
            return;
           // DuckSimulator.Go();
            Class3 ww = new Class3();
            Class2 ss = new Class2();
            Class1 ee = new Class1();
            ee.Register();
            ee.go();
           // ee.go();
            return;
            Linq4Fun linqfun = new Linq4Fun();
            linqfun.TestGroupByOne();
            linqfun.TestGroupByTwo();
            linqfun.TestGroupByThree();
            linqfun.TestGroupByFour();
          
            //状态模式
            MyStateMachine machine = new MyStateMachine(10);
            machine.InsertQuarter();
            machine.InsertQuarter();
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
            machine.TurnCrank(); 
            machine.InsertQuarter();
            machine.TurnCrank(); 
            machine.InsertQuarter();
            machine.TurnCrank(); 
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
            machine.TurnCrank(); 
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
            machine.TurnCrank();
         

            //工厂模式
            Aircraft aircraft = new Aircraft();
            BaseFacroty factory = new FruitFactory();
            IFruit banana = factory.BuyFruit("Banana", "Banana");
            IFruit apple = factory.BuyFruit("Apple", "Apple");
            IFruit apple2 = factory.BuyFruit("Apple", "Apple2");
            IFruit apple3 = factory.BuyFruit("Apple", "Apple3");
            factory.ShowPackage();

            //策略模式
            FruitDestructor destructor = new FruitDestructor(factory);
            destructor.testThrowFruit();

            //桥接模式
            BasicScoreRecorder recoder1 = new BasicScoreRecorder(new BasicOperator());
            recoder1.Work3();
            ClassicScoreRecorder recoder2 = new ClassicScoreRecorder(new ClassicOperator());
            recoder2.Work3();

            //仓库模式
            ClassicFruitRepository Repository = new ClassicFruitRepository();
            Repository.ClassicFunc(new ClassicFruit() { name = "Banana", score = 9999 });
            Repository.Cut();
            Repository.Throw();

            //规约模式
            testSpecification.test();

            //观察者模式
            BllMain.runmain();

            //func?action?
            /*
            Repository.testfunc((args1) => { return args1; });
            Console.WriteLine("whatthefuck".testfunc((o1, o2) => { return o1 + o2; }));

            List<ClassicFruit> list = new List<ClassicFruit>();
            for (int i = 0; i < 999; i++)
            {
                list.Add(new ClassicFruit() { name = i.ToString(), score = i });
            }

            List<ClassicFruit> newlist = list.Where2(o => { return o.score < 100; }).ToList();
            foreach (ClassicFruit c in newlist)
            {
                Console.WriteLine(c.score);
            }
             * */

            Expression<del> myET = x => (x.name == " sd" && x.score == 2) || (x.name == " sd" && (x.score == 2 || x.score == 2));

            int[] sss = { 555, 125, 955, 9, 5, 3, 7, 11, 6, 2, 4, 0, 12, 18, 855, 154, 1024, 5102 };

            sss.quicksort(0, sss.Length - 1);
            sss.ToList().ForEach((o) => { Console.WriteLine(o); });



            List<dynamic> list = new List<dynamic>();

            list.Add(new { id = 1, name = "name" });

            foreach (dynamic i in list)
            {
                Console.WriteLine("拆箱：类型" + i.id.GetType().Name +"值"+ i.id.ToString());
            }
        }
    }

    public static class stringhelper
    {
        public static string testfunc(this string str, Func<string, string, string> convert)
        {
            return convert(str, str);

        }

        public static void testaction(this string str, Action<string, string, string> convert)
        {
            convert(str, str, str);

        }

        public static IEnumerable<TSource> Where2<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
        {
            foreach (TSource s in source)
            {
                if (predicate(s))
                {
                    yield return s;
                }
            }
        }
    }

}
